﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_Flow_AddPostil]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_Flow_AddPostil];
GO
CREATE PROCEDURE [dbo].[sproc_Flow_AddPostil]
    @DocID int,
    @Postiler nvarchar(300),
    @PostilContent ntext,
    @PostilType int,
    @ObjID int =0,
    @ObjType int = 0
    
AS

DECLARE @staff_id int
DECLARE @StepID  int

DECLARE @DefineID int

SELECT     @staff_id = staff_id
    FROM 
        uds_staff
    WHERE     staff_name = @Postiler

IF @staff_id >0 and EXISTS(SELECT 1 FROM uds_flow_document WHERE Doc_ID = @DocID)
BEGIN

SELECT @StepID = Step_ID 
    FROM uds_flow_document 
    WHERE doc_id = @DocID

INSERT INTO uds_flow_postil (Doc_ID,Step_ID,Postiler_ID,Postil_Date,Postil_Content,Postil_Type,Obj_ID,obj_type)
    VALUES(@DocID,@StepID,@staff_id,getdate(),@PostilContent,@PostilType,@ObjID,@objtype)
END


RETURN IDENT_CURRENT('uds_Flow_Postil')